package com.tongfusoft.document.system.service.impl;

import java.sql.Timestamp;
import java.util.Date;

import org.springframework.stereotype.Service;

import com.tongfuosft.document.system.service.IDocSystempParamService;
import com.tongfusoft.da.pagehelper.PageInfo;
import com.tongfusoft.da.template.service.impl.DataTemplateServiceImpl;
import com.tongfusoft.document.entity.SystemParam;
import com.tongfusoft.document.entity.Users;
import com.tongfusoft.exception.ServiceException;
import com.tongfusoft.utils.UIDGeneratorService;

@Service("docSystemParamService")
public class DocSystemParamServiceImpl extends DataTemplateServiceImpl implements IDocSystempParamService{

	@Override
	public void createParam(SystemParam param, Users user) {

		if(super.selectList("systemParamList", param).size()>0){
			
			throw new ServiceException("repeat_error");
		}
		param.setCreatedBy(user.getUserId());
		param.setLastUpdBy(user.getUserId());
		param.setLastUpdDate(new Timestamp(new Date().getTime()));
		param.setCreatedDate(new Timestamp(new Date().getTime()));
		param.setSystemId(UIDGeneratorService.getUUID());
		param.setStatus("1");
		super.insert("addsystemParam", param);
	}

	@Override
	public void deleteParam(SystemParam param, Users user) {
		param.setLastUpdBy(user.getUserId());
		param.setLastUpdDate(new Timestamp(new Date().getTime()));
		super.update("delSystemParam", param);
	}

	@Override
	public void updateParam(SystemParam param, Users user) {

		param.setLastUpdBy(user.getUserId());
		param.setLastUpdDate(new Timestamp(new Date().getTime()));
		super.update("editSystemParam", param);
	}

	@Override
	public SystemParam getParamById(String id) {
		
		SystemParam param = new SystemParam();
		param.setSystemId(id);
		return (SystemParam)super.selectOne("systemParamList", param);
	}

	@Override
	public PageInfo paramList(int pageSize, int pageIndex, SystemParam param) {
		// TODO Auto-generated method stub
		return super.findPage("systemParamList", param, pageSize, pageIndex);
	}

	@Override
	public SystemParam getParamByCode(String systemCode) {
		System.out.println(systemCode+"222");
		SystemParam param = new SystemParam();
		param.setSystemCode(systemCode);
		return (SystemParam)super.selectOne("systemParamList", param);
	}

}
